package com.fyzk.activity.lottery.jc.football.newJz.data;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tyjc.lottery.R;

/**
 * Created by fanxs11 on 16/5/3.
 *
 * 数据分析
 */
public class AnalysisHistoryView extends AnalysisChildView {
    private View childView;

    public AnalysisHistoryView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public AnalysisHistoryView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AnalysisHistoryView(Context context) {
        this(context, null);
    }

    public void initView(){
        super.initView();
        childView = getChildView();
        ll.addView(childView);
    }

    private View getChildView() {
        View childView = LayoutInflater.from(context).inflate(R.layout.jc_analysis_child, null);
        LinearLayout child_ll = (LinearLayout) childView.findViewById(R.id.jc_analysis_child_ll);
        RelativeLayout head_rl = (RelativeLayout) childView.findViewById(R.id.jc_analysis_child_rl);
        head_rl.setVisibility(View.GONE);
        try {
            for (int i = -1; i < ScoreDetailActivity.analyzeResponse.getPreClashMatches().size(); i++) {
                child_ll.addView(getChildItemView(i));
            }
        } catch (Exception e){

        }

        return childView;
    }

    private View getChildItemView(int i){
        View childItemView = LayoutInflater.from(context).inflate(R.layout.jc_analysis_child_item, null);
        TextView tv1 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv1);
        TextView tv2 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv2);
        TextView tv3 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv3);
        TextView tv4 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv4);
        TextView tv5 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv5);
        TextView tv6 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv6);

        if (i == -1) {
            tv1.setBackgroundColor(context.getResources().getColor(R.color.jczq_analysis_bg_gray));
            tv2.setBackgroundColor(context.getResources().getColor(R.color.jczq_analysis_bg_gray));
            tv3.setBackgroundColor(context.getResources().getColor(R.color.jczq_analysis_bg_gray));
            tv4.setBackgroundColor(context.getResources().getColor(R.color.jczq_analysis_bg_gray));
            tv5.setBackgroundColor(context.getResources().getColor(R.color.jczq_analysis_bg_gray));
            tv6.setBackgroundColor(context.getResources().getColor(R.color.jczq_analysis_bg_gray));
        } else {

            JCZQ_AnalyzeResponse.PreClashMatchesBean pre = ScoreDetailActivity.analyzeResponse.getPreClashMatches().get(i);

            tv1.setText(pre.getMatchName());
            tv2.setText(pre.getMatchDate());
            tv3.setText(pre.getHomeTeam());
            tv4.setText(pre.getFinalScore());
            tv5.setText(pre.getAwayTeam());
            tv6.setText(pre.getHfResult());



            if (pre.getHomeTeam().equals(ScoreDetailActivity.matchInfoResponse.getHomeTeam())) {
                tv3.setTextColor(context.getResources().getColor(R.color.jczq_analysis_red));
            } else if (pre.getHomeTeam().equals(ScoreDetailActivity.matchInfoResponse.getAwayTeam())) {
                tv3.setTextColor(context.getResources().getColor(R.color.jczq_analysis_blue));
            }
            if (pre.getAwayTeam().equals(ScoreDetailActivity.matchInfoResponse.getHomeTeam())) {
                tv5.setTextColor(context.getResources().getColor(R.color.jczq_analysis_red));
            } else if (pre.getAwayTeam().equals(ScoreDetailActivity.matchInfoResponse.getAwayTeam())) {
                tv5.setTextColor(context.getResources().getColor(R.color.jczq_analysis_blue));
            }
        }

        return childItemView;
    }

    @Override
    protected void changeData() {
        childView = getChildView();
    }
}
